fix(install): bake DATABASE_URL env into ecosystem config when canonical pgserve is detected - #1604
Conversation
…cal pgserve is detected Closes the wish's "shared backbone" loop for genie. Previously, `genie install` registered genie-serve under pm2 with NO env block — meaning genie-serve always fell back to spawning its own embedded pgserve on `:19644` regardless of whether canonical pgserve was registered. Operators had to hand-edit `~/.genie/genie-serve.config.cjs` to add an env block (caught live on this server during the canonical migration). What changes ------------ - `tryPgservePort()` (new) — probes `pgserve port` to discover the canonical port. Uses the real subcommand (NOT `--version`, which doesn't exist in pgserve@^2.1.0 and false-negatived in `omni doctor --fix` historically). - `buildGenieDatabaseUrl(port)` (new) — composes the canonical URL using the `genie` database (auto-provisioned by pgserve on first connection, mirrors omni's pattern). - `buildEcosystemConfigSource(geniePath, databaseUrl?)` — accepts an optional `databaseUrl` and bakes it into an `env` block when present. Omits the env block entirely when absent (so genie-serve falls back to its embedded auto-spawn path without an empty env clobbering an operator's shell-set DATABASE_URL). - `buildPm2StartArgs(geniePath, databaseUrl?)` and `writeEcosystemConfig(geniePath, databaseUrl?)` — thread the URL through. - `installCommand` — when `tryPgserveInstall()` succeeds AND `tryPgservePort()` returns a valid port, derives the canonical URL and passes it through. Logs the URL on success so operators can see the wire that was made. - The "already installed" early-return now hints `pm2 delete genie-serve && genie install` as the way to refresh env on URL change. Tests ----- - `omits env block when no databaseUrl provided (legacy fallback path)` - `bakes DATABASE_URL into env block when canonical pgserve url provided` - 14/14 tests pass (was 12, +2 new env-wiring tests). - Typecheck green. Linter: no new warnings on changed files. Validated on khal-os -------------------- After hand-editing the ecosystem config to include the env block, genie-serve connects to canonical pgserve via TCP `:8432` and the embedded `:19644` postgres no longer spawns. This PR codifies that hand-edit so future installs are correct out of the box.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5567e202c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!options.skipPgserve) { | ||
| tryPgserveInstall(); | ||
| if (tryPgserveInstall()) { |
There was a problem hiding this comment.
Probe canonical pgserve port even when --skip-pgserve is set
The new DATABASE_URL wiring is fully gated by !options.skipPgserve, so users who intentionally pass --skip-pgserve (documented as “don’t run pgserve install first”) never get canonical URL injection even if pgserve is already running and pgserve port would succeed. In that path, genie-serve falls back to embedded pgserve behavior, which defeats the main goal of this change for operator-managed pgserve setups.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request updates the genie install command to detect a canonical pgserve instance and bake its connection URL into the PM2 ecosystem configuration, ensuring genie-serve uses the shared database backbone. Key changes include new utility functions for port probing, updates to the PM2 configuration logic to support environment variables, and corresponding unit tests. I have no feedback to provide.
Summary
Closes the wish's "shared backbone" loop for genie. Previously,
genie installregistered genie-serve under pm2 with no env block — meaning genie-serve always fell back to spawning its own embedded pgserve on:19644regardless of whether canonical pgserve was registered.Caught live on this server during the canonical migration: I had to hand-edit
~/.genie/genie-serve.config.cjsto add:…otherwise pm2 restored the wrong env on every restart and genie-serve spawned its own embedded pgserve.
Fix
When
pgserve installsucceeds ANDpgserve portreturns a valid port atgenie installtime, derive the canonical URL and bake it into the pm2 ecosystem config'senvblock. Omitted when canonical pgserve isn't available (so genie-serve falls back to its embedded auto-spawn path — same as today).Code shape
tryPgservePort()(new)pgserve portto discover canonical port. Uses the real subcommand (NOT--version— that flag doesn't exist in pgserve@^2.1.0; false-negatived inomni doctor --fixhistorically)buildGenieDatabaseUrl(port)(new)genieDB (pgserve auto-provisions; mirrors omni's pattern)buildEcosystemConfigSource(geniePath, databaseUrl?)envblock. Omits the block when no URL — preventing an empty env from clobbering an operator's shell-setDATABASE_URLbuildPm2StartArgs(geniePath, databaseUrl?)+writeEcosystemConfiginstallCommandpm2 delete genie-serve && genie installfor refreshing envTests
omits env block when no databaseUrl provided (legacy fallback path)bakes DATABASE_URL into env block when canonical pgserve url providedWave context
This is the second post-canonical-pgserve fix needed in genie. Once this lands and a new genie publishes, fresh
genie installcalls auto-wire genie-serve to canonical pgserve — no hand-editing required.Test plan
bun test src/genie-commands/__tests__/install.test.ts— 14/14bun run typecheck— greenbun run lint— no new warnings on changed filespm2 delete genie-serve && genie installshould write the env block;genie-serveshould connect to canonical pgserve on:8432instead of spawning embedded